﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：ConsumptionPeriodsInfo
// 文件功能描述：消费时段设置业务逻辑层
//
// 
// 创建标识：2012-03-23 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class ConsumptionPeriodsInfo
    {
        /// <summary>
        /// 编号
        /// </summary>
        public int PeriodCode
        {
            get;
            set;
        }
        /// <summary>
        /// 时段名称
        /// </summary>
        public string PeriodName
        {
            get;
            set;
        }
        /// <summary>
        /// 开始时间
        /// </summary>
        public string BeginTime
        {
            get;
            set;
        }
        /// <summary>
        /// 结束时间
        /// </summary>
        public string EndTime
        {
            get;
            set;
        }
        /// <summary>
        /// 是否跨天
        /// </summary>
        public string NextDay
        {
            get;
            set;
        }
        /// <summary>
        /// 是否跨天布尔型
        /// </summary>
        public bool blNextDay
        {
            get;
            set;
        }

        private DataAccessConsumptionPeriods dar;
        private int ConsumptionPeriodscount;
        public int _ConsumptionPeriodscount
        {
            get { return ConsumptionPeriodscount; }
        }
        public ConsumptionPeriodsInfo(bool isgetcount)
        {
            dar = new DataAccessConsumptionPeriods();
            if (isgetcount)
            {
                ConsumptionPeriodscount = GetConsumptionPeriodsCount();
            }
        }
        public ConsumptionPeriodsInfo()
        { }
        /// <summary>
        /// 获取消费时段数量
        /// </summary>
        /// <returns></returns>
        private int GetConsumptionPeriodsCount()
        {
            return dar.GetConsumptionPeriodsCount();
        }

        /// <summary>
        /// 获取消费时段信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<ConsumptionPeriodsInfo> SelConsumptionPeriodsInfo(int pagesize, int startindex, string strquery)
        {
            IList<ConsumptionPeriodsInfo> fundlist = new List<ConsumptionPeriodsInfo>();
            ConsumptionPeriodsInfo fundinfo;
            DataSet ds = dar.SelConsumptionPeriodsInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                fundinfo = new ConsumptionPeriodsInfo()
                {
                    PeriodCode = Convert.ToInt32(item["PeriodCode"]),
                    PeriodName = item["PeriodName"].ToString(),
                    BeginTime = item["BeginTime"].ToString(),
                    EndTime = item["EndTime"].ToString(),
                    NextDay = item["NextDay"].ToString(),
                };
                fundlist.Add(fundinfo);
            }
            return fundlist;
        }

        /// <summary>
        /// 根据编号获取一条消费时段信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public ConsumptionPeriodsInfo GetConsumptionPeriodsInfoOne(string ID)
        {
            dar = new DataAccessConsumptionPeriods();
            DataSet ds = dar.GetConsumptionPeriodsInfoOne(ID);
            ConsumptionPeriodsInfo info = new ConsumptionPeriodsInfo();
            info.PeriodCode = int.Parse(ds.Tables[0].Rows[0]["PeriodCode"].ToString());
            info.PeriodName = ds.Tables[0].Rows[0]["PeriodName"].ToString();
            info.BeginTime = ds.Tables[0].Rows[0]["BeginTime"].ToString();
            info.EndTime = ds.Tables[0].Rows[0]["EndTime"].ToString();
            info.NextDay = ds.Tables[0].Rows[0]["NextDay"].ToString();
            return info;
        }

        /// <summary>
        /// 保存消费时段(修改界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveConsumptionPeriodsEdit(ConsumptionPeriodsInfo fund)
        {
            object[] obj = new object[] { fund.PeriodCode, fund.BeginTime, fund.EndTime, fund.blNextDay };
            return dar.SaveConsumptionPeriodsEdit(obj);
        }
    }
}
